#Start-Process powershell -Verb runAs
$SourceRoot = "C:\DanTFS\BizTalkESB\Solutions"

# Variables for BTS 2013
# $NETFXPath= "NETFX 4.0 Tools"
# $SdkKeyName="InstallRoot"
# $WindowsSDKVersionA = "v8.0A"
# $WindowsSDKVersion = "v8.0"


# Variables for BTS 2013 R2
$NETFXPath= "NETFX 4.5.1 Tools"
# $SdkKeyName="InstallRoot"
$WindowsSDKVersionA = "v8.1A"
$WindowsSDKVersion = "v8.1"

# Visual Studio 2012 Path
# $DevEnvPath=(Get-ItemProperty  "hklm:SOFTWARE\Microsoft\VisualStudio\").InstallDir
# Visual Studio 2013 Path
$DevEnvPath=(Get-ItemProperty  "hklm:SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0").InstallDir



if((test-path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSBuild") -eq $True)
{
    Write-Host "64 bit Machine"

    
	$SDKPath=(Get-ItemProperty  "hklm:SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\$WindowsSDKVersionA").InstallationFolder
	Write-Host "$SDKPath"

	if ($SDKPath -eq $null)
	{
	    $SDKPath=(Get-ItemProperty  "hklm:SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\$WindowsSDKVersion").InstallationFolder
        Write-Host "$SDKPath"
	}

    $os=Get-WMIObject win32_operatingsystem    
	if ($os.OSArchitecture -eq "64-bit") {
		$GacUtility = $SDKPath+"bin\"+$NETFXPath+"\x64\gacutil.exe"
	} else { #32 bit OS
		$GacUtility = $SDKPath+"bin\"+$NETFXPath+"\gacutil.exe"
	}

    # GAC ESB EXTENSION LIBRARIES
    Write-Host "Adding BizTalk.ESB.Extensions.AdapterProviders to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\AdapterProviders\bin\Debug\BizTalk.ESB.Extensions.AdapterProviders.dll
    Write-Host
    Write-Host

    Write-Host "Adding BizTalk.ESB.Extensions.ContextAdder to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\ContextAdder\bin\Debug\BizTalk.ESB.Extensions.ContextAdder.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.ExceptionHandling to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\ExceptionHandling\bin\Debug\BizTalk.ESB.Extensions.ExceptionHandling.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.Itinerary to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\Itinerary\bin\Debug\BizTalk.ESB.Extensions.ItineraryOM.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.Helpers to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\Helpers\bin\Debug\BizTalk.ESB.Extensions.Helpers.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.Mapping to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\Mapping\bin\Debug\BizTalk.ESB.Extensions.Mapping.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.MessagingServices to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\MessagingServices\bin\Debug\BizTalk.ESB.Extensions.MessagingServices.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.NamespacePrefix to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\NamespacePrefix\bin\Debug\BizTalk.ESB.Extensions.NamespacePrefix.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding Microsoft.Biztalk.Adapters.Wcf.NullBinding to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\NullBinding\bin\Debug\Microsoft.Biztalk.Adapters.Wcf.NullBinding.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.PipelineComponents to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\PipelineComponents\bin\Debug\BizTalk.ESB.Extensions.PipelineComponents.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.Resolvers to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\Resolvers\bin\Debug\BizTalk.ESB.Extensions.Resolvers.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.Rules to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\Rules\bin\Debug\BizTalk.ESB.Extensions.Rules.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.Validation.Helpers to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\Validation.Helpers\bin\Debug\BizTalk.ESB.Extensions.Validation.Helpers.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.WCFBehaviors to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\WCFBehaviors\bin\Debug\BizTalk.ESB.Extensions.WCFBehaviors.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.SSO.Common to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\SSO.Common\bin\Debug\BizTalk.ESB.Extensions.SSO.Common.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.SSO.Data to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\SSO.Data\bin\Debug\BizTalk.ESB.Extensions.SSO.Data.dll
    Write-Host
    Write-Host
    
    Write-Host "Adding BizTalk.ESB.Extensions.SSO.BizTalk to the GAC..."
    &$GacUtility /if $SourceRoot\BizTalk.ESB.Extensions\Projects\SSO.BizTalk\bin\Debug\BizTalk.ESB.Extensions.SSO.BizTalk.dll
    Write-Host
    Write-Host

}
else
{
    Write-Host "32 bit Machine"
    Write-Host "NOT IMPLEMENTED!!!  No assemblies added to the GAC"
}